#include "sdlSurface.h"

unsigned sdlSurface::counter = 0;
sdlMonitor* sdlSurface::monitor = NULL;

sdlSurface::sdlSurface(){
	if (monitor == NULL){
		monitor = sdlMonitor::getInstance();
	}
	counter++;
	this->surface = NULL;
}

void sdlSurface::applySurface(int x, int y, const sdlSurface& origen, SDL_Rect* clip){
	SDL_Rect offset;
	offset.x = x;
	offset.y = y;
	SDL_BlitSurface(origen.surface, clip, this->surface, &offset);
}

int sdlSurface::width(){
	return this->surface->w;
}

int sdlSurface::height(){
	return this->surface->h;
}

sdlSurface::~sdlSurface(){
	SDL_FreeSurface(this->surface);
	counter--;
	if (counter == 0){
		sdlMonitor::eliminar();
		monitor = NULL;
	}
}
